{extend name="platform/base" /}
{block name="resources"/}
<script src="ADMIN_JS/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.common.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
<style>

</style>

{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 网站设置 </header>
	<input type="hidden" value="{$topic_id}" id="topic_id"/>
	<div class="panel-body">
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">专题名称</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="topic_name" value="{$info['topic_name']}">
					<p class="error">请输入专题名称</p>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">关键字</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="keyword"  value="{$info['keyword']}">
					<p class="error">请输入关键字</p>
				</div>
			</div>
			
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
                <label class="col-lg-2 control-label">描述</label>
                <div class="col-sm-4">
                    <textarea name="store_zy"  rows="5" cols="65" id="desc" class="textarea-common">{$info['desc']}</textarea>
                	<p class="error">请输入专题描述</p>
                </div>
            </div>
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
                  <label class="col-lg-2 control-label">图像</label>
                  <div class="col-md-2">
					<p class="imglogo-box">
						<img id="preview_picture_img" src="{:__IMG($info['picture_img'])}" class="imglogo" />
						<p class="error">请上传图像</p>
		
					</p>
                    <a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                    <span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                    <input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadpicture" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;" onchange="imgUpload(this);"> 
					<input type="hidden" id="picture_img" value="{$info['picture_img']}">
					</span>
					
					<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
					    
					    </a>
					    
				</div>
           </div>
           <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="col-lg-2 control-label">条幅</label>
                       <div class="col-md-2">
						<p class="imglogo-box">
						<img id="preview_scroll_img" src="{:__IMG($info['scroll_img'])}" class="imglogo"/>
						<p class="error">请上传条幅</p>
						</p>
                           <a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                            <span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                            <input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadscroll" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;" onchange="imgUpload(this);">
							<input type="hidden" id="scroll_img" value="{$info['scroll_img']}">
							</span>
						
							<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
						</a>
					</div>
              </div>
              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="col-lg-2 control-label">背景图</label>
                       <div class="col-md-2">
						<p class="imglogo-box"><img id="preview_background_img"  src="{:__IMG($info['background_img'])}"  class="imglogo"/></p>
                           <a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                            <span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                            <input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadbackground" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;" onchange="imgUpload(this);">
							<input type="hidden" id="background_img" value="{$info['background_img']}">
							</span>
							
							<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
							
						</a>
						<p class="error">请上传背景图</p>
					</div>
              </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">背景色</label>
				<div class="col-md-4">
					<input type="color" id="background_color" maxlength="10" class="input-common-color" value="{$info.background_color}"/>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">有效时间</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="start_time" style="width:100px;display:inline-block;"; {if condition='$info["start_time"] != 0'}value="{$info.start_time|date='Y-m-d',###}"{/if}; onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">-
					<input type="text" class="form-control" id="end_time" style="width:100px;display:inline-block;"; {if condition='$info["end_time"] != 0'}value="{$info.end_time|date='Y-m-d',###}"{/if}; onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
					<p class="error">请输入活动有效期</p>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">专题介绍</label>
				<div class="col-md-4">
					<script id="editor" type="text/plain" style="width: 100%;height:300px;">{$info.introduce}</script>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否显示头部</label>
				<div class="col-md-4">
					  <label for="navigationtype1" class="radio-label"><input type="radio" value="1" name="navigationtype" id="is_head" {if condition="$info['is_head'] eq 1"}checked{/if}/>开启</label>
				      <label for="navigationtype2" class="radio-label"><input type="radio" value="2" name="navigationtype" id="is_head" {if condition="$info['is_head'] eq 0"}checked{/if}/>关闭</label>
		 	     	  <p class="error">是否显示头部</p>
		 	     </div>
		 	     
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否显示底部</label>
				 <div class="col-md-4">
					  <label for="waptype1" class="radio-label"><input type="radio" value="1" name="waptype" id="is_foot" {if condition = "$info['is_foot'] eq 1"}checked{/if}/>开启</label>
			      	  <label for="waptype2" class="radio-label"><input type="radio" value="2" name="waptype" id="is_foot" {if condition = "$info['is_foot'] eq 0"}checked{/if}/>关闭</label>
		 	     	  <p class="error">是否显示底部</p>
		 	     </div>

			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">


				<div class="form-group">
					<label class="col-sm-2 control-label">&nbsp;&nbsp;电脑端:</label>
					<div class="col-md-">
						  {$template_url['pc_template_url']}&nbsp;<input type="text" class="input-common" name="" id="pc_topic_template" value="{$template_url['pc_file']}" style="width: 400px;" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">&nbsp;.html
					      <p class="hint">用户自定义模板必须存放在{$template_url['pc_template_url']}下，模板名只能由英文组成</p>
						  <p class="error">电脑端模板不能为空</p>
			 	     </div>
			 	     
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">&nbsp;&nbsp;手机端:</label>
					<div class="col-md-10">
						  {$template_url['wap_template_url']}&nbsp;<input type="text" class="input-common" name="" id="wap_topic_template" value="{$template_url['wap_file']}" style="width: 400px;" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">&nbsp;.html
						  <p class="hint">用户自定义模板必须存放在{$template_url['wap_template_url']}下，模板名只能由英文组成</p>
						  <p class="error">手机端模板不能为空</p>
			 	     </div>
			 	     <input type="hidden" id="t_id" value="{$info.topic_id}">
				</div>
				 
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="addTopic()" class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
{/block}
{block name="script"}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
<script src="__STATIC__/kindeditor/lang/zh_cn.js" charset="utf-8"></script>
<script type="text/javascript">
var ue = UE.getEditor('editor',{
	toolbars : [
		[ 'source', // 源代码
		'bold', // 加粗
		'italic', // 斜体
		'underline', // 下划线
		'strikethrough', // 删除线
		'forecolor', // 字体颜色
		'backcolor', // 背景色
		'fontfamily', // 字体
		'fontsize', // 字号
		'paragraph', // 段落格式
		'justifyleft', // 居左对齐
		'justifycenter', // 居中对齐
		'justifyright', // 居右对齐
		'superscript', // 上标
		'blockquote', // 引用
		'selectall', // 全选
		'preview', // 预览
		'removeformat', // 清除格式
		'inserttable', // 插入表格
		'unlink', // 取消链接
		'insertrow', // 前插入行
		'insertcol', // 前插入列
		'mergeright', // 右合并单元格
		'mergedown', // 下合并单元格
		'deleterow', // 删除行
		'deletecol', // 删除列
		'splittorows', // 拆分成行
		'splittocols', // 拆分成列
		'splittocells', // 完全拆分单元格
		'deletecaption', // 删除表格标题
		'inserttitle', // 插入标题
		'mergecells', // 合并多个单元格
		'deletetable', // 删除表格
		'cleardoc', // 清空文档
		 //'simpleupload', // 单图上传
		'insertimage', // 多图上传
		'link', // 超链接
		'emotion', // 表情
		'insertorderedlist', // 有序列表
		'insertunorderedlist', // 无序列表
		'fullscreen', // 全屏
		'directionalityltr', // 从左向右输入
		'directionalityrtl', // 从右向左输入
		'imagenone', // 默认
		'imageleft', // 左浮动
		'imageright', // 右浮动
		// 'attachment', // 附件
		'imagecenter', // 居中
		'lineheight', // 行间距
		'customstyle', // 自定义标题
		]]
});

$(function(){
	UE.getEditor('editor').addListener( 'ready', function() {
		if($("#content").val()){
			UE.getEditor('editor').setContent($("#content").val());
		}
	} );
})
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = new Object();
	var id = $(event).next().attr("id");
	var only_type = $(event).attr('only-type');
	if(!only_type){
		data.file_path = UPLOADCOMMON;
	}else{
		data.file_path = UPLOADFILE;
	}
	uploadFile(fileid,data,function(res){
		
		if(res.code){
			$("#" + id).val(res.data);
			$("#text_" + id).val(res.data);
			$("#preview_"+ id).attr("src",__IMG(res.data));
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

var flag = false;//防止重复提交

//保存
function addTopic(){
	var topic_id=$("#t_id").val();
	var topic_name = $("#topic_name").val();
	var keyword = $("#keyword").val();
	var desc = $("#desc").val();
	var picture_img = $("#picture_img").val();
	var scroll_img = $("#scroll_img").val();
	var background_img = $("#background_img").val();
	var background_color = $("#background_color").val();
	var start_time = $("#start_time").val();
	var end_time = $("#end_time").val();
	var pc_topic_template = $("#pc_topic_template").val();
	var wap_topic_template = $("#wap_topic_template").val();
	var content = UE.getEditor('editor').getContent();
	var range_type = 0;
	var goods_id_array = '';
	if(content.length>30000){
		showTip("文章内容太长","warning");
		return;
	}
	var is_head = $("#is_head:checked").val() ? 1 : 0;
	var is_foot = $("#is_foot:checked").val() ? 1 : 0;
	if(!verify(topic_name, picture_img, scroll_img, start_time, end_time, pc_topic_template, wap_topic_template)){
		return false;
	}
	
	if(flag){
		return;
	}

	flag = true;
	$.ajax({
		type : "post",
		url : "{:__URL('PLATFORM_MAIN/promotion/updateTopic')}",
		data : {
			"topic_name" : topic_name,
			"keyword" :  keyword,
			"desc" : desc,
			"picture_img" : picture_img,
			"scroll_img" : scroll_img,
			"background_img" :  background_img,
			"background_color" : background_color,
			"start_time" : start_time,
			"end_time" : end_time,
			"content" : content,
			"range_type" : range_type,
			"goods_id_array" : '',
			"is_head" : is_head,
			'is_foot' : is_foot,
			'pc_topic_template' : pc_topic_template,
			'wap_topic_template' : wap_topic_template,
			'topic_id' : topic_id
			
 		},
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/promotion/topiclist')}");
			}else{
				showMessage('error', data["message"]);
				flag = false;
			}
		}
	});
}

function verify(topic_name, picture_img, scroll_img, start_time, end_time, pc_topic_template, wap_topic_template){
	if(topic_name == ''){
		$("#topic_name").parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(picture_img == ''){
		$("#picture_img").parent().parent().parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(scroll_img == ''){
		$("#scroll_img").parent().parent().parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(start_time == '' || end_time == ''){
		$("#start_time").parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(start_time == '' || end_time == ''){
		$("#start_time").parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(pc_topic_template == ''){
		$("#pc_topic_template").parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	if(wap_topic_template == ''){
		$("#wap_topic_template").parent().find('.error').show();
		return false;
	}else{
		$(".error").hide();
	}
	return true;
}
</script>
{/block}